package com.trestristesmicos.anahuac;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;

public class AnahuacActivity extends Activity  {
	
	  private GridView gridview;
	  
	  // references to our images
      private Integer[] mThumbIds = {
      		R.drawable.menu_01, R.drawable.menu_02,
      		R.drawable.menu_03, R.drawable.menu_04,
      		R.drawable.menu_05, R.drawable.menu_06,
      		R.drawable.menu_07, R.drawable.menu_08,
      		R.drawable.menu_09, R.drawable.menu_10,
      		R.drawable.menu_11, R.drawable.menu_12,
      		R.drawable.menu_13, R.drawable.menu_14,
      		R.drawable.menu_15, R.drawable.menu_16,
      		R.drawable.menu_17, R.drawable.menu_18,
      		R.drawable.menu_19, R.drawable.menu_20
      };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        
        gridview = (GridView) findViewById(R.id.Gridview_Inicial);
        gridview.setAdapter(new ImageAdapter(this));
        gridview.setOnItemClickListener(new OnItemClickListener() {
        	
			public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
        		animatedStartActivity(position);
			}
        });        
    }    	
    
    @Override
	protected void onResume() {
		// animateIn this activity
		ActivitySwitcher.fadeIn(findViewById(R.id.container), getWindowManager());
		super.onResume();
	}
    
    private void animatedStartActivity(int position) {
		// we only animateOut this activity here.
		// The new activity will animateIn from its onResume() - be sure to implement it.
		
    	final Intent intent;
    	
    	switch (position) {
    	
    	case 0:
    		intent = new Intent(getApplicationContext(), HistoriaActivity.class);
			// disable default animation for new intent
			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
			
				public void onAnimationFinished() {
					startActivity(intent);
				}
			});
    		break;
    	
    	case 2:
    		intent = new Intent(getApplicationContext(), ProgramasActivity.class);
			// disable default animation for new intent
			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
				
				public void onAnimationFinished() {
					startActivity(intent);
				}
			});
    		break;
    	case 6:
    		intent = new Intent(getApplicationContext(), TalleresActivity.class);
			// disable default animation for new intent
			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
				
				public void onAnimationFinished() {
					startActivity(intent);
				}
			});
    		break;
		case 8:
			intent = new Intent(getApplicationContext(), RegistroActivity.class);
			// disable default animation for new intent
			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
				
				public void onAnimationFinished() {
					startActivity(intent);
				}
			});
						
			break;

		case 12:
			intent = new Intent(getApplicationContext(), ApoyosActivity.class);
			// disable default animation for new intent
			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
				
				public void onAnimationFinished() {
					startActivity(intent);
				}
			});
						
			break;

		case 14:
			intent = new Intent(getApplicationContext(), ExtranjeroActivity.class);

			// disable default animation for new intent
			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
			
				public void onAnimationFinished() {
					startActivity(intent);
				}
			});
						

			break;	
		  		

		case 10:
			intent = new Intent(getApplicationContext(), Test.class);
			// disable default animation for new intent
			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
		
				public void onAnimationFinished() {
					startActivity(intent);
				}
		});
						
			break;
			
		case 16:
			intent = new Intent(getApplicationContext(), RegistroAlumnoPotencialActivity.class);
		// disable default animation for new intent
		intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
			
				public void onAnimationFinished() {
					startActivity(intent);
			}
		});
						
			break;
			
		case 18:
			intent = new Intent(getApplicationContext(), VideoActivity.class);
		// disable default animation for new intent
		intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
			String video = (String)"android.resource://com.trestristesmicos.anahuac/" + R.raw.anahuac ;
			intent.putExtra("uriVideo",video);
			
			ActivitySwitcher.fadeOut(findViewById(R.id.container), getWindowManager(), new ActivitySwitcher.AnimationFinishedListener() {
				
				public void onAnimationFinished() {
					startActivity(intent);
			}
		});
						
			break;
   	}      
}
   
    
    public class ImageAdapter extends BaseAdapter {
        private Context mContext;

        public ImageAdapter(Context c) {
            mContext = c;
        }

       
        public int getCount() {
            return mThumbIds.length;
        }

        
        public Object getItem(int position) {
            return null;
        }

        
        public long getItemId(int position) {
            return 0;
        }

       
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            
       	            
            if (convertView == null) {  // if it's not recycled, initialize some attributes
            	
            	imageView = new ImageView(mContext);
                imageView.setLayoutParams(new GridView.LayoutParams(256, 190));
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(0, 0, 0, 0);

            } else {
                imageView = (ImageView) convertView;
            }
            
           imageView.setImageResource(mThumbIds[position]);
            return imageView;
        }
    }
  
}
